﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Door_Case : SimpleItems_Animator
{
    [SerializeField] private bool isOpen = false;
    [SerializeField] CaseManager caseManager;
    protected override void Awake()
    {
        base.Awake();
        if (!isOpen)
        {
            PlayAnimator();
        }
    }
    public override void Interactive()
    {
        if (caseManager==null|| caseManager.NeedSaveBird <= caseManager.SavedBird)
        {
            base.Interactive();
        }
    }

    protected override void OnAnimationStart()
    {
        
    }

    protected override void OnAnimationEnd()
    {
        isOpen = !isOpen;
        if (caseManager!=null)
        {
            caseManager.GoNextCase();
        }
        
    }

    int num = 0;
    protected override void OnTriggerStay2D(Collider2D collision)
    {
        if (caseManager != null)
        {
            if (caseManager.NeedSaveBird <= caseManager.SavedBird)
            {
                base.OnTriggerStay2D(collision);
            }
        }
        else
        {
            base.OnTriggerStay2D(collision);
        }

        if (isOpen&&caseManager != null && num == 2)
        {
            caseManager.GoNextCase();
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        num++;
    }
    protected override void OnTriggerExit2D(Collider2D collision)
    {
        base.OnTriggerExit2D(collision);
        if (collision.CompareTag(TagAndLayersConfigs.Tag.Player))
        {
            num--;
        }
    }

}
